﻿/**
 * 
 * F. Mehmet ARSLAN (c) 2015
 * fmehmetarslan46@gmail.com
 *  
 **/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ServiceState.Models;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using ServiceState.Helper;
using System.Web.Caching;
using System.Net;
using System.Text;
namespace ServiceState.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View(StateControl.GetServicesState);
        }

        public String stateLog(int line)
        {
            StringBuilder sbLog = new StringBuilder();
            String[] logLines = LogManager.GetLog(); ;
            for (var i = line; i < logLines.Length; i++)
            {
                int urlStart = logLines[i].IndexOf("http");
                String logLine= logLines[i].Substring(0, urlStart);
                logLine=logLine.Replace("InternalServerError[500]", "<span class='http-internal-server-error'>InternalServerError[500]</span>");
                logLine=logLine.Replace("OK[200]", "<span class='http-ok'>OK[200]</span>");
                logLine = logLine.Replace("Unauthorized[401]", "<span class='http-unauthorized'>Unauthorized[401]</span>");
                sbLog.Append(logLine);
                sbLog.Append("<a target='_blank' href='");
                String url = logLines[i].Substring(urlStart);
                sbLog.Append(url);
                sbLog.Append("'>");
                sbLog.Append(url);
                sbLog.AppendLine("</a>");
                sbLog.AppendLine("<br/>");
            }
            return sbLog.ToString();
        }
        
        public JsonResult StateService()
        {
            return Json(StateControl.ServiceStateList, JsonRequestBehavior.AllowGet);
        }
    }
}
